package com.easylinkin.linkappapi.alarm.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.alarm.entity.AlarmPersonContact;
import com.easylinkin.linkappapi.alarm.service.AlarmPersonContactService;
import com.easylinkin.linkappapi.annotation.CommonOperateLogAnnotate;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.operatelog.constant.LogConstant.LogModule;
import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

@RestController
@Api(value="告警联系人",tags={"告警联系人"})
@RequestMapping("/alarm/alarmPersonContact")
public class AlarmPersonContactController {
    @Autowired
    private AlarmPersonContactService alarmPersonContactService;

    /**
     * 获得告警联系人列表信息 分页
     * @param requestModel
     * @return
     */
    @ApiOperation("获得告警联系人列表信息 分页")
    @PostMapping("getPage")
    public RestMessage getPage(@RequestBody RequestModel<AlarmPersonContact> requestModel) {
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        IPage<AlarmPersonContact> record = alarmPersonContactService.getAlarmPersonContacts(requestModel.getPage(), requestModel.getCustomQueryParams());
        return RestBuilders.successBuilder().data(record).build();
    }

    /**
     * 获得告警联系人列表信息
     * @param alarmPersonContact
     * @return
     */
    @ApiOperation("获得告警联系人列表信息")
    @PostMapping("get")
    public RestMessage get(@RequestBody AlarmPersonContact alarmPersonContact) {
        Assert.notNull(alarmPersonContact, "alarmPersonContact 不能为空");
        List<AlarmPersonContact> record = alarmPersonContactService.getAlarmPersonContacts(alarmPersonContact);
        return RestBuilders.successBuilder().data(record).build();
    }

    /**
     * 根据id删除删除告警联系人
     * @param alarmPersonContact
     * @return
     */
    @ApiOperation("根据id删除删除告警联系人")
    @PostMapping("deleteAlarmPersonContactById")
    @CommonOperateLogAnnotate(module = LogModule.ALARM_PERSON_CONTACT, desc = "删除告警联系人")
    public RestMessage deleteAlarmPersonContactById(@RequestBody AlarmPersonContact alarmPersonContact) {
        Assert.notNull(alarmPersonContact.getId(), "联系人ID不能为空");
        return RestBuilders.successBuilder(alarmPersonContactService.deleteAlarmPersonContactById(alarmPersonContact.getId())).build();
    }

    /**
     * 新增告警联系人
     * @param alarmPersonContact
     * @return
     */
    @ApiOperation("新增告警联系人")
    @PostMapping("add")
    @CommonOperateLogAnnotate(module = LogModule.ALARM_PERSON_CONTACT, desc = "新增告警联系人")
    public RestMessage addAlarmPersonContact(@RequestBody AlarmPersonContact alarmPersonContact) {

        return RestBuilders.successBuilder(alarmPersonContactService.addAlarmPersonContact(alarmPersonContact)).build();
    }

    /**
     * 更新告警联系人
     * @param alarmPersonContact
     * @return
     */
    @ApiOperation("更新告警联系人")
    @PutMapping("update")
    @CommonOperateLogAnnotate(module = LogModule.ALARM_PERSON_CONTACT, desc = "修改告警联系人")
    public RestMessage updateAlarmPersonContact(@RequestBody AlarmPersonContact alarmPersonContact) {

        return RestBuilders.successBuilder(alarmPersonContactService.updateAlarmPersonContact(alarmPersonContact)).build();
    }
}
